home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / Commands / ServerObject-FormCmnPHP.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  47.7 KB  |  1,662 lines

  1. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3.     
  4. //**********************GLOBAL VARS********************
  5.  
  6. // intialize labels
  7. var TEXTFIELD     =  MM.LABEL_TextField;
  8. var HIDDENFIELD   =  MM.LABEL_HiddenField;
  9. var PASSWORDFIELD =  MM.LABEL_PasswordField;
  10. var PASSWORD      =  MM.LABEL_Password;
  11. var FILEFIELD     =  MM.LABEL_FileField;
  12. var TEXTAREA      =  MM.LABEL_TextArea;
  13. var MENU          =  MM.LABEL_Menu;
  14. var CHECKBOX      =  MM.LABEL_CheckBox;
  15. var RADIOGROUP    =  MM.LABEL_RadioGroup;
  16. var STATICTEXT    =  MM.LABEL_Text;
  17.  
  18. var TEXT          =  "',none,none";
  19. var NUMERIC       =  "none,0,NULL";
  20. var DATE          =  "',none,NULL";
  21. var CHECKBOXYN    =  "none,Y,N";
  22. var CHECKBOX10    =  "none,1,0";
  23. var CHECKBOXNEG10 =  "none,-1,0";
  24. var DOUBLE        =  "none,.,NULL";
  25.  
  26. var STR_DIVIDER = "* *";
  27. var STR_ELEMENT_NAMES = STR_DIVIDER;
  28.  
  29. var DB_UNSUPPORTED_COLUMNS_ENUM_MAP = null;
  30.  
  31. //--------------------------------------------------------------------
  32. // FUNCTION:
  33. //   createFormElementStrings
  34. //
  35. // DESCRIPTION:
  36. //   This function creates the form element strings that will be used
  37. //   to create the final form.
  38. //
  39. // ARGUMENTS:
  40. //   none
  41. //
  42. // RETURNS:
  43. //   nothing
  44. //--------------------------------------------------------------------
  45. function createFormElementStrings(rowInfoArr)
  46. {
  47.   var nRows = rowInfoArr.length, i,currRowInfoObj;
  48.   var fieldInfoObj, fieldType, fieldLabel, fieldVal;
  49.   var formElemObj, formElemStrArr = new Array(), formElemStr;
  50.  
  51.   for (i = 0; i < nRows; i++)
  52.   {
  53.     fieldType = "", fieldLabel = "";
  54.     
  55.     currRowInfoObj = rowInfoArr[i];
  56.     fieldInfoObj = currRowInfoObj.displayAs; 
  57.     fieldInfoObj.fieldName = currRowInfoObj.fieldName;
  58.     fieldLabel = currRowInfoObj.label;    
  59.     fieldVal = fieldInfoObj.value;         
  60.     fieldType = fieldInfoObj.type;
  61.     
  62.     formElemObj = new Object();    
  63.     formElemObj.ElementName = fieldInfoObj.fieldName;
  64.     formElemObj.ElementType = fieldType.toLowerCase();
  65.     formElemObj.ElementValue = fieldVal;
  66.     formElemObj.ElementLabel = fieldLabel;
  67.     formElemObj.EqualToVal = "";
  68.     
  69.     if (fieldType == "checkBox")
  70.     {
  71.       formElemObj.ElementChecked = "";
  72.       if (fieldInfoObj.checked)
  73.       {
  74.         formElemObj.ElementChecked = "checked";
  75.       }
  76.     }
  77.     else if (fieldType == "text")
  78.     {
  79.       formElemObj.ElementValue = fieldInfoObj.text;
  80.     }
  81.     else if (fieldType == "dynamicCheckBox")
  82.     {  
  83.       formElemObj.ElementChecked = "";
  84.       if(fieldInfoObj.checkIf)
  85.       {
  86.         var selObj = new Object();
  87.         selObj.expression1 = dwscripts.encodeDynamicExpression(fieldInfoObj.checkIf); 
  88.         selObj.expression2 = dwscripts.encodeDynamicExpression(fieldInfoObj.equalTo); 
  89.         formElemObj.ElementChecked = extPart.getInsertString("", "dynamicCheckbox_attrib", selObj, "");
  90.       }
  91.     }
  92.     else if (fieldType == "menu")
  93.     {
  94.       var nOptions = fieldInfoObj.textArr.length;
  95.       var defaultSelected = fieldInfoObj.defaultSelected;
  96.       
  97.       if (!nOptions) 
  98.       {
  99.          var labelText = "[ " + MM.LABEL_Label + " ]";
  100.          fieldInfoObj.textArr = new Array(labelText, labelText);
  101.          fieldInfoObj.valArr   = new Array("menuitem1","menuitem2");
  102.          nOptions = 2;
  103.       }      
  104.       
  105.       formElemObj.OptionText = fieldInfoObj.textArr;
  106.       formElemObj.OptionValue = fieldInfoObj.valArr;
  107.  
  108.       var optionSelectedArr = new Array();
  109.       // This logic checks if the selected field is same as the value,
  110.       // if so marks it as selected, otherwise adds an empty string.
  111.       // this logic is required because all the arrays should be of same
  112.       // length for loop in edml file
  113.       for(var j = 0; j < nOptions; j++)
  114.       {
  115.         if(fieldInfoObj.valArr[j] && defaultSelected)
  116.         {
  117.           var selObj = new Object;
  118.           selObj.DefaultSelected = defaultSelected;
  119.           selObj.ItemValue = (fieldInfoObj.valArr[j])? dwscripts.encodeDynamicExpression(fieldInfoObj.valArr[j]):fieldInfoObj.valArr[j];
  120.           var expr = extPart.getInsertString("", "Menu_OptionSelected", selObj, "");
  121.           optionSelectedArr.push(expr);
  122.         }
  123.         else
  124.         {
  125.           optionSelectedArr.push("");
  126.         }
  127.       }
  128.       formElemObj.OptionSelected = optionSelectedArr;  
  129.     }
  130.     else if (fieldType == "dynamicMenu")
  131.     {
  132.       var equalTo = fieldInfoObj.defaultSelected;    
  133.       formElemObj.DynOptionText = fieldInfoObj.textCol;
  134.       formElemObj.DynOptionValue = fieldInfoObj.valCol;
  135.       formElemObj.EqualToVal = (equalTo)? dwscripts.encodeDynamicExpression(equalTo):equalTo; 
  136.       formElemObj.RecordsetName = fieldInfoObj.recordset;    
  137.     }
  138.     else if (fieldType == "radioGroup")
  139.     {
  140.       var nButtons = fieldInfoObj.labelArr.length;
  141.       var defaultChecked = fieldInfoObj.defaultChecked;
  142.       
  143.       if (!nButtons) 
  144.       {
  145.          var labelText = "[ " + MM.LABEL_Label + " ]";
  146.          fieldInfoObj.labelArr = new Array(labelText, labelText);
  147.          fieldInfoObj.valArr   = new Array("radiobutton1","radiobutton2");
  148.          nButtons = 2;
  149.       }
  150.       
  151.       formElemObj.FieldLabel = fieldInfoObj.labelArr;
  152.       formElemObj.FieldValue = fieldInfoObj.valArr;
  153.     
  154.       var fieldCheckedArr = new Array();
  155.       
  156.       // This logic checks if the checked field is same as the value,
  157.       // if so marks it as checked, otherwise adds an empty string.
  158.       // this logic is required because all the arrays should be of same
  159.       // length for a loop in edml file
  160.       for(j = 0;j < nButtons; j++)
  161.       {
  162.         if(fieldInfoObj.valArr[j] && defaultChecked)
  163.         {
  164.           var selObj = new Object;
  165.           selObj.DefaultChecked = dwscripts.encodeDynamicExpression(defaultChecked);
  166.           selObj.ItemValue = dwscripts.encodeDynamicExpression(fieldInfoObj.valArr[j]);
  167.           var expr = extPart.getInsertString("", "Radio_OptionChecked", selObj, "");
  168.           fieldCheckedArr.push(expr);
  169.         }
  170.         else
  171.         {
  172.           fieldCheckedArr.push("");
  173.         }
  174.       }
  175.       formElemObj.FieldChecked = fieldCheckedArr;       
  176.     }
  177.     else if (fieldType == "dynamicRadioGroup")
  178.     {
  179.       var equalTo = fieldInfoObj.defaultChecked;        
  180.       formElemObj.DynFieldName = fieldInfoObj.labelCol;
  181.       formElemObj.DynFieldValue = fieldInfoObj.valCol;
  182.       formElemObj.EqualToVal = (equalTo)? dwscripts.encodeDynamicExpression(equalTo):equalTo;
  183.       formElemObj.RecordsetName = fieldInfoObj.recordset;     
  184.     }
  185.     
  186.     
  187.     formElemStr = extPart.getInsertString("", "EditOp-FormElement", formElemObj, "");
  188.     formElemStrArr.push(formElemStr);
  189.   }
  190.   
  191.   return formElemStrArr;
  192. }
  193.  
  194.  
  195. //*-------------------------------------------------------------------
  196. // FUNCTION:
  197. //   wrapNamesWithSpaces
  198. //
  199. // DESCRIPTION:
  200. //   this fn is needed for SQL statements,
  201. //   names with spaces need brackets around them
  202. //
  203. // ARGUMENTS:
  204. //   nameStr - the name to wrap
  205. //
  206. // RETURNS:
  207. //   string - the wrapped name
  208. //--------------------------------------------------------------------
  209. function wrapNamesWithSpaces(nameStr){
  210.   var hasSpaces = ( nameStr.indexOf(" ") != -1 );
  211.   return (hasSpaces)? "[" + nameStr + "]" : nameStr;
  212.  
  213. }
  214.  
  215.  
  216. //*-------------------------------------------------------------------
  217. // FUNCTION:
  218. //   browseFile
  219. //
  220. // DESCRIPTION:
  221. //  Invokes dialog to allow user to select filename. Puts value in text input.
  222. //  The optional flag stripParameters will remove anything after a question
  223. //  mark if it is set to true
  224. //
  225. // ARGUMENTS:
  226. //   fieldToStoreURL 
  227. //   stripParameters - boolean flag to remove anything after a question
  228. //   mark
  229. //
  230. // RETURNS:
  231. //   string - the wrapped name
  232. //--------------------------------------------------------------------
  233. function browseFile(fieldToStoreURL, stripParameters) {
  234.   var fileName = "";
  235.   fileName = browseForFileURL();  //returns a local filename
  236.   if (stripParameters) {
  237.     var index = fileName.indexOf("?");
  238.     if (index != -1) {
  239.       fileName = fileName.substring(0,index);
  240.     }
  241.   }
  242.   if (fileName) fieldToStoreURL.value = fileName;
  243. }
  244.  
  245.  
  246. //--------------------------------------------------------------------
  247. // FUNCTION:
  248. //   populateColumnGrid
  249. //
  250. // DESCRIPTION:
  251. //   This function is called by updateUI function.  It is responsible
  252. //   for populating the Column grid.
  253. //
  254. // ARGUMENTS:
  255. //   none
  256. //
  257. // RETURNS:
  258. //   nothing
  259. //--------------------------------------------------------------------
  260. function populateColumnGrid()
  261. {
  262.   // clear additional column list
  263.   // it lists columns that don't get populated in the grid, and needs to be cleared
  264.   updateAdditionalColumnList('clear'); 
  265.     
  266.     // if there are no tables, then clear grid
  267.   if ( !connectionHasBeenChosen() )
  268.   {
  269.     _ColumnNames.setAllRows(new Array(),new Array());
  270.     return;
  271.   }
  272.  
  273.   var colsAndTypes = MMDB.getColumnAndTypeOfTable(_ConnectionName.getValue(), _TableName.getValue());
  274.   ColumnTypes = new Array();  // clear the column types map
  275.   var rowTextArr = new Array();
  276.   var rowValArr  = new Array();
  277.  
  278.   for (var i=0; i < colsAndTypes.length; i+=2)
  279.   {
  280.     ColumnTypes[colsAndTypes[i]] = colsAndTypes[i+1];
  281.     
  282.     if (EDIT_OP_TYPE == "Update") 
  283.     {
  284.       rowInfo = getRowTextAndValue(colsAndTypes[i], colsAndTypes[i+1], _RecordsetName.getValue(), _UniqueKeyColumn.getValue());
  285.     } 
  286.     else 
  287.     {  
  288.       // if Insert (and recordset menu does not exist)
  289.       rowInfo = getRowTextAndValue(colsAndTypes[i],colsAndTypes[i+1]);
  290.     }
  291.     rowTextArr.push(rowInfo[0]);
  292.     rowValArr.push(rowInfo[1]);
  293.   }
  294.  
  295.   _ColumnNames.setAllRows(rowTextArr, rowValArr);
  296.     
  297.   // clear global field names array (used to check for dupe field names)
  298.   STR_ELEMENT_NAMES = STR_DIVIDER;    
  299. }
  300.  
  301. //--------------------------------------------------------------------
  302. // FUNCTION:
  303. //   checkForUnsupportedColumnTypes
  304. //
  305. // DESCRIPTION:
  306. //   This function checks if all the columns are supported or not,
  307. //   displaying a message
  308. //
  309. // ARGUMENTS:
  310. //   Boolean - to display alert message or not
  311. //
  312. // RETURNS:
  313. //   Nothing
  314. //--------------------------------------------------------------------
  315. function checkForUnsupportedColumnTypes(displayMsg)
  316. {   
  317.   // check for the colTypes to make sure we support them, if not
  318.   // the flow is that they don't appear in the form fields grids,
  319.   // But we do display a message saying that they are not displayed,
  320.   // but the user can add them manually by clicking on the + button...
  321.   var unsupportedColTypes = new Array();
  322.   var unsupportedColNames = new Array();
  323.   
  324.   for(var i = 0; i < _ColumnNames.valueList.length; i++)
  325.   {
  326.     var rowInfoObj = _ColumnNames.valueList[i];
  327.     if (rowInfoObj && rowInfoObj.colType)
  328.     {
  329.       if (!isColTypeSupported(rowInfoObj.colType))
  330.       {
  331.         unsupportedColTypes.push(rowInfoObj.colType);
  332.         unsupportedColNames.push(rowInfoObj);
  333.       }
  334.     }
  335.   }  
  336.   
  337.   if (unsupportedColTypes.length && unsupportedColNames.length)
  338.   {
  339.     if(displayMsg)
  340.       alert(dwscripts.sprintf(MM.Msg_UnsupportedColumnsInTable, unsupportedColTypes));
  341.     for(var i = 0; i < unsupportedColNames.length; i++)
  342.     {
  343.       // select the row that is to be deleted...
  344.       _ColumnNames.pickRowValue(unsupportedColNames[i]);
  345.       deleteGridRow();    
  346.     }
  347.   }
  348.  
  349. }
  350.  
  351. //--------------------------------------------------------------------
  352. // FUNCTION:
  353. //   isColTypeSupported
  354. //
  355. // DESCRIPTION:
  356. //   This function returns if the colType is supported by UD or not.
  357. //
  358. // ARGUMENTS:
  359. //   colType - string - column type for update
  360. //
  361. // RETURNS:
  362. //   boolean
  363. //--------------------------------------------------------------------
  364. function isColTypeSupported(colType)
  365. {
  366.   var retVal = true;
  367.   if (DB_UNSUPPORTED_COLUMNS_ENUM_MAP == null)
  368.   {
  369.     buildUnsupportedColumnsEnum();
  370.   }
  371.   
  372.   var unsupportedCol = DB_UNSUPPORTED_COLUMNS_ENUM_MAP[colType.toLowerCase()]  
  373.   if (unsupportedCol)
  374.   {
  375.     // col is not supported,,,
  376.     retVal = false;
  377.   }
  378.   else
  379.   {
  380.     retVal = true;
  381.   }   
  382.   
  383.   return retVal;  
  384. }
  385.  
  386. //--------------------------------------------------------------------
  387. // FUNCTION:
  388. //   buildUnsupportedColumnsEnum
  389. //
  390. // DESCRIPTION:
  391. //   This function returns if the colType is supported by UD or not.
  392. //
  393. // ARGUMENTS:
  394. //   colType - string - column type for update
  395. //
  396. // RETURNS:
  397. //   boolean
  398. //--------------------------------------------------------------------
  399. function buildUnsupportedColumnsEnum()
  400. {
  401.     if (DB_UNSUPPORTED_COLUMNS_ENUM_MAP == null)
  402.     {
  403.       // TODO: read in from a configuration file
  404.       var a = new Array();
  405.       a["binary"] = 128; 
  406.       a["varbinary"] = 204;
  407.       a["longvarbinary"] = 204; 
  408.       a["longbinary"] = 205; // matched to longvarbinary
  409.                 
  410.       //oracle
  411.       a["raw"]  = 204;// Match it to Binary
  412.       a["nclob"]  = 204;//Match it to Binary
  413.       a["bfile"]  = 204;//Match it to Binary
  414.       a["ref cursor"] = 900; //Arbitrary ID Val
  415.       a["refcursor"] = 900;
  416.       // SQL Server 7
  417.       a["image"]  =  204 ;// binary
  418.       
  419.       DB_UNSUPPORTED_COLUMNS_ENUM_MAP = a;
  420.     }
  421. }
  422.  
  423.  
  424. //--------------------------------------------------------------------
  425. // FUNCTION:
  426. //   getRowTextAndValue
  427. //
  428. // DESCRIPTION:
  429. //   This function returns the information for a row in the column table.
  430. //
  431. // ARGUMENTS:
  432. //   colName - string - column name
  433. //   colType - string - column type
  434. //   rsName  - string - (optional) recordset name, only needed for update
  435. //   uniqueColName - string - (optional) Unique Key Column, only needed
  436. //                            for update
  437. //
  438. // RETURNS:
  439. //   array of 2 values
  440. //--------------------------------------------------------------------
  441. function getRowTextAndValue(colName, colType, rsName, uniqueColName)
  442. {
  443.   var retVal = new Array(2);
  444.   var colFieldType = "", colSubmitType = "", colSubmitName = "";
  445.   
  446.   var colLabel = getLabelFromColumnName(colName);
  447.   
  448.   var fieldName = getElementNameFromColumnName(colName);
  449.   // if update, the unique key column should be a static text...
  450.   if (EDIT_OP_TYPE == "Update" && colName == uniqueColName)
  451.   {
  452.     colFieldType = STATICTEXT;
  453.   }
  454.   else
  455.   {
  456.     // default to password display type if "password" appears in field name
  457.     if (colName.toLowerCase().indexOf(PASSWORD) != -1)
  458.     {
  459.       colFieldType = PASSWORDFIELD;
  460.     }
  461.     else
  462.     {
  463.       colFieldType = getFieldTypeFromColumnType(colType);
  464.     }
  465.   }
  466.   
  467.   var colSubmitType = getSubmitTypeFromColumnType(colType);
  468.   var colSubmitName = getSubmitNameFromSubmitType(colSubmitType);   
  469.  
  470.   var colDisplayAs = getFormFieldStorageObjectFromFormFieldType(colFieldType);
  471.   
  472.   // disable the _SubmitAs field if it is for the Primary Key column
  473.   if (EDIT_OP_TYPE == "Update" && colName == uniqueColName)
  474.   {
  475.     UniqueColSubmitAs = colSubmitType;
  476.     colSubmitType = "";  
  477.     colSubmitName = "";
  478.     toggleSubmitAs(false); // enable or disable Submit As Menu
  479.     toggleLabelVisibility(colDisplayAs);    // enable or disable Label textfield
  480.   }
  481.   
  482.   var rowText = colName + "|" + colLabel + "|" + colFieldType + "|" + colSubmitName;
  483.  
  484.   var rowValObj = new Object();  
  485.   rowValObj.column = colName;
  486.   rowValObj.label = colLabel;
  487.   rowValObj.displayAs = colDisplayAs;
  488.   rowValObj.submitAs = colSubmitType;
  489.   rowValObj.fieldName = fieldName;
  490.   rowValObj.defaultStr = "";
  491.   rowValObj.passwordStr = "";
  492.   rowValObj.colType = colType;
  493.   
  494.   // populate storage object with any default values
  495.   if (EDIT_OP_TYPE == "Update" && rowValObj.displayAs.type != "passwordField")
  496.   {
  497.     var rs = (rsName)?rsName:_RecordsetName.getValue();
  498.     rowValObj = populateFormFieldStorageType(rowValObj,rs,colName);
  499.   }
  500.  
  501.   retVal[0] = rowText;
  502.   retVal[1] = rowValObj;
  503.             
  504.   return retVal;
  505. }
  506.  
  507. //--------------------------------------------------------------------
  508. // FUNCTION:
  509. //   getLabelFromColumnName
  510. //
  511. // DESCRIPTION:
  512. //
  513. // ARGUMENTS:
  514. //
  515. // RETURNS:
  516. //   Nothing
  517. //--------------------------------------------------------------------
  518. function getLabelFromColumnName(colName)
  519. {
  520.   return colName.charAt(0).toUpperCase() + colName.substring(1) + MM.LABEL_Delimiter;      
  521. }
  522.  
  523. //--------------------------------------------------------------------
  524. // FUNCTION:
  525. //   getElementNameFromColumnName
  526. //
  527. // DESCRIPTION:
  528. //
  529. // ARGUMENTS:
  530. //   col - string - the column name to create an element name from
  531. //
  532. // RETURNS:
  533. //   string -  the element name
  534. //--------------------------------------------------------------------
  535. function getElementNameFromColumnName(col)
  536. {
  537.   var elemName = col;
  538.   var counter = 2;
  539.   var divider = STR_DIVIDER;
  540.  
  541.   // replace spaces with underscores
  542.   elemName = elemName.replace(/ /g, "_");
  543.   
  544.   // strip out all characters that are not alpha-numeric, or underscores
  545.   elemName = elemName.replace(/[^a-zA-Z_0-9]/g, "");
  546.   
  547.   // don't allow the first character to be numeric
  548.   while (parseInt(elemName.charAt(0)) &&
  549.          parseInt(elemName.charAt(0)) == elemName.charAt(0) )
  550.   {
  551.     elemName = elemName.substring(1);
  552.   }
  553.  
  554.   // in the unlikely case that no characters are left after the above,
  555.   // then name element generically as "element"
  556.   if (elemName.length == 0)
  557.   {
  558.     elemName = MM.LABEL_Element;
  559.   }
  560.  
  561.   // ensure that name is not a dupe
  562.   var tempName = elemName; 
  563.   while (STR_ELEMENT_NAMES.indexOf(divider + elemName + divider) != -1)
  564.   {
  565.     elemName = tempName + counter++;
  566.   }
  567.  
  568.   // add name to global names list
  569.   STR_ELEMENT_NAMES += elemName + divider;
  570.  
  571.   return elemName;
  572. }
  573.  
  574. //--------------------------------------------------------------------
  575. // FUNCTION:
  576. //   getFieldTypeFromColumnType
  577. //
  578. // DESCRIPTION:
  579. //   This function returns the field type based on the given column type
  580. //
  581. // ARGUMENTS:
  582. //   colType - string - the column type returned from MMDB
  583. //
  584. // RETURNS:
  585. //   Nothing
  586. //--------------------------------------------------------------------
  587. function getFieldTypeFromColumnType(colType)
  588. {
  589.   return (dwscripts.isBooleanDBColumnType(colType)) ? CHECKBOX : TEXTFIELD;
  590. }
  591.  
  592. //--------------------------------------------------------------------
  593. // FUNCTION:
  594. //   getSubmitTypeFromColumnType
  595. //
  596. // DESCRIPTION:
  597. //   This function is called when the grid is populated, to choose a 
  598. //   submit type based on the column type
  599. //
  600. //   Note: this function is used during initial population only.
  601. //         getSubmitTypeBasedOnElementType() is used when the 
  602. //         element type is changed
  603. //
  604. // ARGUMENTS:
  605. //   colType - string - the column type returned from MMDB
  606. //
  607. // RETURNS:
  608. //   nothing
  609. //--------------------------------------------------------------------
  610. function getSubmitTypeFromColumnType(colType)
  611. {
  612.   var retVal = "";
  613.   var colIsDouble = dwscripts.isDoubleDBColumnType(colType);
  614.   var colIsNumeric = dwscripts.isNumericDBColumnType(colType);
  615.   var colIsDate    = dwscripts.isDateDBColumnType(colType);
  616.   var colIsBoolean = dwscripts.isBooleanDBColumnType(colType);
  617.   // added condition for currency...skarra
  618.   var colIsCurrency = dwscripts.isCurrencyDBColumnType(colType);
  619.  
  620.   if ( colIsDouble )
  621.   {
  622.       retVal = DOUBLE;
  623.   }
  624.   else if ( colIsNumeric )
  625.   {
  626.     retVal = (colIsBoolean) ? CHECKBOX10 : NUMERIC;
  627.   }
  628.   else if ( colIsDate )
  629.   {
  630.     retVal = DATE;
  631.   }
  632.   else if (colIsCurrency)
  633.   {
  634.     retVal = NUMERIC;
  635.   }
  636.   else
  637.   { // if text-based
  638.     retVal = (colIsBoolean) ? CHECKBOXYN : TEXT;
  639.   }
  640.   
  641.   return retVal;
  642. }
  643.  
  644. //--------------------------------------------------------------------
  645. // FUNCTION:
  646. //   getSubmitTypeBasedOnElementType
  647. //
  648. // DESCRIPTION:
  649. //   Called when the element type is changed, to update the submit type
  650. //
  651. // ARGUMENTS:
  652. //   submitType - string - the current submit type
  653. //   elemType - string - the current element type
  654. //   colType - string - the current column type
  655. //
  656. // RETURNS:
  657. //   Nothing
  658. //--------------------------------------------------------------------
  659. function getSubmitTypeBasedOnElementType(submitType, elemType, colType)
  660. {
  661.   var newSubmitType = submitType;
  662.   
  663.   // don't bother if conection hasn't been chosen
  664.   if ( connectionHasBeenChosen() )
  665.   {
  666.     var colIsNumeric = dwscripts.isNumericDBColumnType(colType);
  667.     var colIsDate    = dwscripts.isDateDBColumnType(colType);
  668.  
  669.     if ( elemType == CHECKBOX )
  670.     { 
  671.       // if display element is a checkbox
  672.       if (colIsNumeric)
  673.       {
  674.         newSubmitType = CHECKBOX10;
  675.       }
  676.       else
  677.       {
  678.         newSubmitType = CHECKBOXYN;
  679.       }
  680.     }
  681.     else
  682.     { // display type does not equal checkbox
  683.  
  684.       // if submit type is currently a checkbox type,
  685.       // then change it back to the most appropriate
  686.       // non-checkbox type
  687.  
  688.       if (submitType==CHECKBOXYN    || submitType==CHECKBOX10 ||
  689.           submitType==CHECKBOXNEG10)
  690.       {
  691.         if (colIsNumeric)
  692.         {
  693.           newSubmitType = NUMERIC;
  694.         }
  695.         else if (colIsDate)
  696.         {
  697.           newSubmitType = DATE;
  698.         }
  699.         else
  700.         {
  701.           newSubmitType = TEXT;
  702.         }
  703.       }
  704.     }
  705.   }
  706.   
  707.   return newSubmitType;
  708. }
  709.  
  710.  
  711. //--------------------------------------------------------------------
  712. // FUNCTION:
  713. //   getSubmitNameFromSubmitType
  714. //
  715. // DESCRIPTION:
  716. //   Returns the display string that should be used for the given
  717. //   submit as type
  718. //
  719. // ARGUMENTS:
  720. //   submitType - string - the comma separated list of submit values
  721. //
  722. // RETURNS:
  723. //   string
  724. //--------------------------------------------------------------------
  725. function getSubmitNameFromSubmitType(submitType)
  726. {
  727.   var submitTypeLabels = _SubmitAs.get('all');
  728.   var submitTypeValues = _SubmitAs.getValue('all');
  729.   
  730.   var submitName = "";
  731.   
  732.   var index = dwscripts.findInArray(submitTypeValues, submitType);
  733.   if (index >= 0)
  734.   {
  735.     submitName = submitTypeLabels[index];
  736.   }
  737.   else
  738.   {
  739.     submitName = submitTypeLabels[0];
  740.   }
  741.   
  742.   return submitName;
  743. }
  744.  
  745. //--------------------------------------------------------------------
  746. // FUNCTION:
  747. //   getFormFieldStorageObjectFromFormFieldType
  748. //
  749. // DESCRIPTION:
  750. //   This function returns a field storage object, based on the 
  751. //   given field type.
  752. //
  753. // ARGUMENTS:
  754. //   fieldType - string - the field type selected in the UI
  755. //
  756. // RETURNS:
  757. //   object
  758. //--------------------------------------------------------------------
  759. function getFormFieldStorageObjectFromFormFieldType(fieldType)
  760. {
  761.   var retObj = "";
  762.  
  763.   if (fieldType == STATICTEXT)
  764.   {
  765.     retObj = new eoText();
  766.   }
  767.   else if (fieldType == TEXTFIELD)
  768.   {
  769.     retObj = new eoTextField();
  770.   }
  771.   else if (fieldType == HIDDENFIELD)
  772.   {
  773.     retObj = new eoHiddenField();
  774.   }
  775.   else if (fieldType == PASSWORDFIELD)
  776.   {
  777.     retObj = new eoPasswordField();
  778.   }
  779.   else if (fieldType == FILEFIELD)
  780.   {
  781.     retObj = new eoFileField();
  782.   }
  783.   else if (fieldType == TEXTAREA)
  784.   {
  785.     retObj = new eoTextArea();
  786.   }
  787.   else if (fieldType == MENU)
  788.   {
  789.     retObj = new eoMenu();
  790.   }
  791.   else if (fieldType == RADIOGROUP)
  792.   {
  793.     retObj = new eoRadioGroup();
  794.   }
  795.   else if (fieldType == CHECKBOX)
  796.   {
  797.     retObj = (EDIT_OP_TYPE == "Insert")?new eoCheckBox():new eoDynamicCheckBox();
  798.   } 
  799.  
  800.   return retObj;
  801. }
  802.  
  803. //--------------------------------------------------------------------
  804. // FUNCTION:
  805. //   displayGridFieldValues
  806. //
  807. // DESCRIPTION:
  808. //   This function is called when the user clicks on a new row in the 
  809. //   grid, changes the values of the UI fields to display the correct
  810. //   information
  811. //
  812. // ARGUMENTS:
  813. //   None
  814. //
  815. // RETURNS:
  816. //   Nothing
  817. //--------------------------------------------------------------------
  818. function displayGridFieldValues()
  819.   // don't bother if grid is empty -- needed because this fn is also
  820.   // called when the connection or table changes
  821.   if (_ColumnNames.list.length == 0)
  822.   {
  823.     _ElementLabel.value = "";
  824.   }
  825.   else
  826.   {
  827.     var currRowText = _ColumnNames.getRow();
  828.     var currRowVal  = _ColumnNames.getRowValue();
  829.     
  830.     var rowTextTokens = getTokens(currRowText,"|");
  831.  
  832.     // TODO: this should be taken from the record, not the display
  833.     _ElementLabel.value = rowTextTokens[1]; // update label field
  834.     _DisplayAs.pickValue(rowTextTokens[2]); // update display menu
  835.  
  836.     // change UI at bottom of dialog, if relevent
  837.     // for instance, if prior row had displayAs = Text, but this row has displayAs = Menu
  838.     showDifferentParams(); 
  839.  
  840.     if (dwscripts.findDOMObject("SubmitAs")) 
  841.     {
  842.       _SubmitAs.pickValue(currRowVal.submitAs); // update submit menu
  843.     }
  844.  
  845.     // fill in form parameters at bottom of UI
  846.     // note that in the case of radio or menu, there is nothing to fill in
  847.     switch (currRowVal.displayAs.type)
  848.     {
  849.     case "text":
  850.       dwscripts.findDOMObject("Text").value = currRowVal.displayAs.text = currRowVal.defaultStr;
  851.       break;
  852.     case "textArea":
  853.     case "textField":
  854.     case "hiddenField":
  855.     case "fileField":
  856.       dwscripts.findDOMObject("SetValueTo").value = currRowVal.displayAs.value = currRowVal.defaultStr;
  857.       break;
  858.     case "passwordField":
  859.       dwscripts.findDOMObject("SetValueTo").value = currRowVal.displayAs.value = currRowVal.passwordStr;
  860.       break;
  861.     case "checkBox": 
  862.       // note: dwscripts.findDOMObject doesn't work with radios, so manual references are needed
  863.       var InitialStateRadios = document.forms[0].InitialState;
  864.       if ( currRowVal.displayAs.checked.toString() == "true")
  865.       {
  866.         InitialStateRadios[0].checked = true; InitialStateRadios[1].checked = false;
  867.       }
  868.       else
  869.       {
  870.         InitialStateRadios[0].checked = false; InitialStateRadios[1].checked = true;
  871.       }
  872.       break;
  873.  
  874.     case "dynamicCheckBox":
  875.       dwscripts.findDOMObject("CheckIf").value = currRowVal.displayAs.checkIf;
  876.       dwscripts.findDOMObject("EqualTo").value = currRowVal.displayAs.equalTo;
  877.       break;
  878.  
  879.     case "default":
  880.       break; 
  881.     }
  882.   }
  883. }
  884.  
  885. //--------------------------------------------------------------------
  886. // FUNCTION:
  887. //   showDifferentParams
  888. //
  889. // DESCRIPTION:
  890. //   This function shows form field specific parameters at the bottom
  891. //   of the dialog for instance, shows "Menu Properties" button for 
  892. //   menu, value field for textfield, etc
  893. //
  894. // ARGUMENTS:
  895. //   displayDefaultStr - Column Name
  896. //
  897. // RETURNS:
  898. //   Nothing
  899. //--------------------------------------------------------------------
  900. function showDifferentParams(displayDefaultStr)
  901. {
  902.   // don't bother if connection has not been chosen
  903.   if ( connectionHasBeenChosen() )
  904.   {
  905.     //EnableDisableUpDownBtns();
  906.     
  907.     //EnableDisableAddDelBtns();
  908.     
  909.     var displayAs = _DisplayAs.getValue()?_DisplayAs.getValue():"none";
  910.     var tables = domUIPieces.getElementsByTagName("TABLE"), param, i;
  911.     var mmParamsTag = document.getElementsByTagName("mmParams").item(0);
  912.  
  913.     var rowInfoObj = _ColumnNames.getRowValue();
  914.     if (EDIT_OP_TYPE == "Update" && rowInfoObj.fieldName == _UniqueKeyColumn.getValue())
  915.     {
  916.       toggleSubmitAs(false);
  917.     }
  918.     else
  919.     {
  920.       toggleSubmitAsVisibility(displayAs); // enable or disable Submit As Menu
  921.       toggleLabelVisibility(displayAs);    // enable or disable Label textfield
  922.     }
  923.  
  924.     if (displayAs == TEXTFIELD || displayAs == TEXTAREA || displayAs == HIDDENFIELD ||
  925.       displayAs == PASSWORDFIELD || displayAs == FILEFIELD)
  926.     {
  927.       param = "textField";
  928.     }
  929.     else if (displayAs == STATICTEXT)
  930.     {
  931.       param = "text";
  932.     }
  933.     else if (displayAs == RADIOGROUP)
  934.     {
  935.       param = "radio";
  936.     }
  937.     else if (displayAs == MENU)
  938.     {
  939.       param = "menu";
  940.     }
  941.     else if (displayAs == CHECKBOX)
  942.     {
  943.       param = (EDIT_OP_TYPE == "Insert") ? "checkBox" : "dynamicCheckBox";
  944.     }
  945.     else if (displayAs == "none")
  946.     {
  947.       param = "none";
  948.     }
  949.  
  950.     for (i=0;i<tables.length;i++)
  951.     {
  952.       if (tables[i].name && tables[i].name == param)
  953.       {
  954.         mmParamsTag.innerHTML = tables[i].innerHTML;
  955.         break;
  956.       }
  957.     }
  958.     // if display as equals text, text area, or text field, and the display as menu has
  959.     // just been changed, then display the default text for this column
  960.     if (displayDefaultStr)
  961.     {
  962.       var rowInfoObj = _ColumnNames.getRowValue();
  963.       var defaultStr = _ColumnNames.getRowValue().defaultStr;
  964.       var passwordStr = _ColumnNames.getRowValue().passwordStr;
  965.       if ( displayAs == TEXTFIELD || displayAs == TEXTAREA ||
  966.         displayAs == HIDDENFIELD || displayAs == FILEFIELD )
  967.       {
  968.         dwscripts.findDOMObject("SetValueTo").value = rowInfoObj.displayAs.value = defaultStr;  // set UI
  969.       }
  970.       else if ( displayAs == PASSWORDFIELD )
  971.       {
  972.         dwscripts.findDOMObject("SetValueTo").value = rowInfoObj.displayAs.value = passwordStr;    // set UI
  973.       }
  974.       else if ( displayAs == STATICTEXT )
  975.       {
  976.         dwscripts.findDOMObject("Text").value = rowInfoObj.displayAs.text = defaultStr;    // set UI
  977.       }
  978.       else if ( param == "dynamicCheckBox" )
  979.       {
  980.         dwscripts.findDOMObject("CheckIf").value = rowInfoObj.displayAs.checkIf = defaultStr;
  981.       }
  982.     }
  983.   }
  984. }
  985.  
  986. //--------------------------------------------------------------------
  987. // FUNCTION:
  988. //   addGridRow
  989. //
  990. // DESCRIPTION:
  991. //   This function is called if there are columns not already 
  992. //   displayed in the grid pop up the "Add Columns" dialog, and allow
  993. //   the user to add them
  994. //
  995. // ARGUMENTS:
  996. //   None
  997. //
  998. // RETURNS:
  999. //   Nothing
  1000. //--------------------------------------------------------------------
  1001. function addGridRow()
  1002. {
  1003.   // check to see if there are columns to add first
  1004.   if (ColumnsToAdd.length == 0)
  1005.   {
  1006.     alert(MM.MSG_NoMoreColumnsToAdd);
  1007.     return;
  1008.   }
  1009.   var addedCols = dwscripts.callCommand("Add Column.htm", ColumnsToAdd);
  1010.   if (!addedCols) return; // user clicked Cancel
  1011.   var nCols = addedCols.length,i, currCol, rowInfoArr;
  1012.  
  1013.   for (i=0;i<nCols;i++)
  1014.   {
  1015.     currCol = addedCols[i];
  1016.     rowInfoArr = getRowTextAndValue(currCol,ColumnTypes[currCol]);
  1017.     _ColumnNames.addRow(rowInfoArr[0],rowInfoArr[1]);
  1018.     updateAdditionalColumnList('del',currCol);
  1019.   }
  1020. }
  1021.  
  1022. //--------------------------------------------------------------------
  1023. // FUNCTION:
  1024. //   deleteGridRow
  1025. //
  1026. // DESCRIPTION:
  1027. //   This function is called when the user clicks the "-" image button
  1028. //
  1029. // ARGUMENTS:
  1030. //  None
  1031. //
  1032. // RETURNS:
  1033. //   Nothing
  1034. //--------------------------------------------------------------------
  1035. function deleteGridRow()
  1036. {
  1037.   var currRow = _ColumnNames.getRow();
  1038.   var currCol = currRow.substring(0,currRow.indexOf("|") );
  1039.   var nRows = _ColumnNames.list.length;
  1040.  
  1041.   if (nRows > 1)
  1042.   {
  1043.     updateAdditionalColumnList('add',currCol);
  1044.     _ColumnNames.delRow();
  1045.     displayGridFieldValues(); 
  1046.   }
  1047.   else
  1048.   {
  1049.     alert(MM.MSG_NeedOneColumnInList);
  1050.   }
  1051. }
  1052.  
  1053. //--------------------------------------------------------------------
  1054. // FUNCTION:
  1055. //   updateGridRow
  1056. //
  1057. // DESCRIPTION:
  1058. //   This function is called whenever the label, submitAs, or displayAs
  1059. //   fields are edited updates both the actual text display in the grid, 
  1060. //   and the object that stores the information about the display
  1061. //
  1062. // ARGUMENTS:
  1063. //   whichColumn: the parameter which has been edited -- displayAs, 
  1064. //   submitAs, or label
  1065. //
  1066. // RETURNS:
  1067. //   Nothing
  1068. //--------------------------------------------------------------------
  1069. function updateGridRow(whichColumn)
  1070. {
  1071.   // check that connection has been chosen before proceeding
  1072.   if ( !connectionHasBeenChosen() )
  1073.   {
  1074.     alert( MM.MSG_NoDataSourceSelected );
  1075.     // _DisplayAs.setIndex(0); // set display menu back to first item
  1076.     return;
  1077.   }
  1078.  
  1079.   var currRowObj  = _ColumnNames.getRowValue();
  1080.   var currRowText = _ColumnNames.getRow();
  1081.   var currColName = currRowText.substring(  0,currRowText.indexOf("|")  );
  1082.  
  1083.   // update grid row text
  1084.   var newRowText = currColName + "|" + _ElementLabel.value + "|" + _DisplayAs.get() + "|"; 
  1085.   newRowText += (dwscripts.findDOMObject("SubmitAs")) ? _SubmitAs.get() : "";
  1086.   _ColumnNames.setRow(newRowText);
  1087.  
  1088.   // update object that stores information about grid row
  1089.   // this object is stored in a value attribute of the Grid object
  1090.   // these objects are stored in an array: GridObj.valueList
  1091.  
  1092.   switch (whichColumn)
  1093.   {
  1094.   case "label":
  1095.     currRowObj.label = _ElementLabel.value;
  1096.     break;
  1097.  
  1098.   case "submitAs":
  1099.     currRowObj.submitAs = _SubmitAs.getValue();
  1100.     break;
  1101.  
  1102.   case "displayAs": 
  1103.     currRowObj.displayAs = getFormFieldStorageObjectFromFormFieldType(_DisplayAs.getValue());
  1104.     // need to update submit property, because changing displayAs menu can
  1105.     // auto-change submit type
  1106.     if ( dwscripts.findDOMObject("SubmitAs") )
  1107.     {
  1108.       currRowObj.submitAs = _SubmitAs.getValue();
  1109.     }
  1110.  
  1111.     var defaultStr = currRowObj.defaultStr;
  1112.     var passwordStr = currRowObj.passwordStr;
  1113.     var fieldType = currRowObj.displayAs.type;
  1114.  
  1115.     if ( fieldType == "textField"  || fieldType == "hiddenField" || 
  1116.       fieldType == "fileField"  ||  fieldType == "textArea" )
  1117.     {
  1118.       currRowObj.displayAs.value = defaultStr;
  1119.     }
  1120.     else if ( fieldType == "passwordField")
  1121.     {
  1122.       currRowObj.displayAs.value = passwordStr;          
  1123.     }
  1124.     else if ( fieldType == "text")
  1125.     {
  1126.       currRowObj.displayAs.text = defaultStr;
  1127.     }
  1128.     else if ( fieldType == "menu")
  1129.     {
  1130.       currRowObj.displayAs.defaultSelected = defaultStr;
  1131.     }
  1132.     else if ( fieldType == "radioGroup")
  1133.     {
  1134.       currRowObj.displayAs.defaultChecked = defaultStr;
  1135.     }
  1136.     else if (fieldType == "dynamicCheckBox")
  1137.     {
  1138.       currRowObj.displayAs.checkIf = defaultStr;
  1139.     }
  1140.     break;
  1141.  
  1142.   default:
  1143.     break;
  1144.   }
  1145. }
  1146.  
  1147. //--------------------------------------------------------------------
  1148. // FUNCTION:
  1149. //   popUpFormFieldPropertiesDialog
  1150. //
  1151. // DESCRIPTION:
  1152. //   It pops up the Radio or Menu Properties dialog, and passes in the 
  1153. //   current menu/radio storage object so that the dialog can be 
  1154. //   initialized correctly
  1155. //
  1156. // ARGUMENTS:
  1157. //   whichOne - String that can be "Radio" or "Menu"
  1158. //
  1159. // RETURNS:
  1160. //   Nothing
  1161. //--------------------------------------------------------------------
  1162. function popUpFormFieldPropertiesDialog(whichOne)
  1163. {
  1164.   var commandFileName = "ServerObject-" + whichOne + "Props.htm";
  1165.   var rowObj = _ColumnNames.getRowValue();
  1166.   var fieldInfoObj = dwscripts.callCommand(commandFileName,rowObj.displayAs)
  1167.  
  1168.  
  1169.   // note: use the "type" property on the menuInfoObj to see which
  1170.     // type of object was returned
  1171.     if (fieldInfoObj)
  1172.   {
  1173.     rowObj.displayAs = fieldInfoObj;
  1174.   }
  1175. }
  1176.  
  1177. //--------------------------------------------------------------------
  1178. // FUNCTION:
  1179. //   updateAdditionalColumnList
  1180. //
  1181. // DESCRIPTION:
  1182. //   The + button calls up an Add Columns dialog, allowing
  1183. //   the user to add additional columns to the list. When the Add Columns
  1184. //   dialog is called, it is populated with the "additional columns list".
  1185. //   This list is updated when a user adds or deletes a column from the UI.
  1186. //
  1187. // ARGUMENTS:
  1188. //   action - Action argument that can Add, Del or Clear
  1189. //   col    - Column
  1190. //
  1191. // RETURNS:
  1192. //   Nothing
  1193. //--------------------------------------------------------------------
  1194. function updateAdditionalColumnList(action, col)
  1195. {
  1196.   if (action == 'add')
  1197.   {
  1198.     ColumnsToAdd.push(col);
  1199.   }
  1200.   else if ( action == 'clear')
  1201.   {
  1202.     ColumnsToAdd = new Array();
  1203.   }
  1204.   else
  1205.   { // delete an item from additional column list
  1206.     for (var i=0; i < ColumnsToAdd.length; i++)
  1207.     {
  1208.       if (ColumnsToAdd[i] == col)
  1209.       {
  1210.         ColumnsToAdd.splice(i,1);
  1211.         break;
  1212.       }
  1213.     }
  1214.   }
  1215. }
  1216.  
  1217. //--------------------------------------------------------------------
  1218. // FUNCTION:
  1219. //   connectionHasBeenChosen
  1220. //
  1221. // DESCRIPTION:
  1222. //   This function is called when the grid is populated, to choose a 
  1223. //   submit type based on the column type
  1224. //
  1225. // ARGUMENTS:
  1226. //   None
  1227. //
  1228. // RETURNS:
  1229. //   Nothing
  1230. //--------------------------------------------------------------------
  1231. function connectionHasBeenChosen()
  1232. {
  1233.   return (_ConnectionName.getValue());
  1234. }
  1235.  
  1236. //--------------------------------------------------------------------
  1237. // FUNCTION:
  1238. //   checkThatCursorIsNotInsideOfAForm
  1239. //
  1240. // DESCRIPTION:
  1241. //   Before inserting a form, check that cursor is not inside of 
  1242. //   an existing form. If it is, set IP location to be just after the form
  1243. //
  1244. // ARGUMENTS:
  1245. //   None
  1246. //
  1247. // RETURNS:
  1248. //   Nothing
  1249. //--------------------------------------------------------------------
  1250. function checkThatCursorIsNotInsideOfAForm()
  1251. {
  1252.   var dom = dw.getDocumentDOM();
  1253.   var formNode = findForm(dom);
  1254.  
  1255.   if (formNode)
  1256.   { // if inside of a form tag
  1257.     formArr = dom.nodeToOffsets(formNode);
  1258.     dom.setSelection(formArr[1]+1,formArr[1]+1);
  1259.   }
  1260. }
  1261.  
  1262. //--------------------------------------------------------------------
  1263. // FUNCTION:
  1264. //   findForm
  1265. //
  1266. // DESCRIPTION:
  1267. //   Before inserting a form, check that cursor is not inside of 
  1268. //   an existing form. If it is, set IP location to be just after the form
  1269. //
  1270. // ARGUMENTS:
  1271. //   dom - DOM object
  1272. //
  1273. // RETURNS:
  1274. //   formObj
  1275. //--------------------------------------------------------------------
  1276. function findForm(dom)
  1277. {
  1278.   var formObj="";
  1279.   var selArr = dom.getSelection();
  1280.   var selObj = dom.offsetsToNode(selArr[0],selArr[1]);
  1281.  
  1282.   while (formObj=="" && selObj.parentNode)
  1283.   {
  1284.     if (selObj.nodeType == Node.ELEMENT_NODE && selObj.tagName=="FORM")
  1285.       formObj=selObj;
  1286.     else
  1287.       selObj = selObj.parentNode;
  1288.   }
  1289.  
  1290.   return formObj;
  1291. }
  1292.  
  1293. //--------------------------------------------------------------------
  1294. // FUNCTION:
  1295. //   toggleSubmitAsVisibility
  1296. //
  1297. // DESCRIPTION:
  1298. //   toggles the visibility of "Submit As: [menu]" that appears on 
  1299. //   the UI.  This menu should be visible for all items except text
  1300. //
  1301. // ARGUMENTS:
  1302. //   displayAs
  1303. //
  1304. // RETURNS:
  1305. //   Nothing
  1306. //--------------------------------------------------------------------
  1307. function toggleSubmitAsVisibility(displayAs)
  1308. {
  1309.   var currentVal = _SubmitAs.getValue();
  1310.   if ( displayAs != STATICTEXT && (currentVal == " " || !currentVal))
  1311.   { // if any form field is chosen in displayAs menu
  1312.     _SubmitAs.enable();
  1313.     _SubmitAs.del();
  1314.     var submitType = getSubmitTypeFromColumnType(ColumnTypes[_ColumnNames.getRowValue().column]);
  1315.     _SubmitAs.pickValue(submitType);
  1316.   }
  1317.   else if (displayAs == STATICTEXT)
  1318.   { // if plain text was chosen in displayAs menu
  1319.     _SubmitAs.append(" ");
  1320.     _SubmitAs.disable();
  1321.   }
  1322. }
  1323.  
  1324. //--------------------------------------------------------------------
  1325. // FUNCTION:
  1326. //   toggleLabelVisibility
  1327. //
  1328. // DESCRIPTION:
  1329. //   toggles the visibility of "Label: [textfield]" that appears on
  1330. //   the UI.  This textfield should be visible for all items except 
  1331. //   hidden fields
  1332. //
  1333. // ARGUMENTS:
  1334. //   displayAs
  1335. //
  1336. // RETURNS:
  1337. //   Nothing
  1338. //--------------------------------------------------------------------
  1339. function toggleLabelVisibility(displayAs)
  1340. {
  1341.   var labelFieldIsVisible = !( _ElementLabel.disabled == "true");
  1342.  
  1343.   if (displayAs != HIDDENFIELD && !labelFieldIsVisible)
  1344.   { // if non-hidden field & non-visible label field
  1345.     _ElementLabel.removeAttribute("disabled")                     // then make label field visible
  1346.       _ElementLabel.setAttribute("value",_ColumnNames.getRowValue().label); // and set value of it 
  1347.  
  1348.   }
  1349.   else if (displayAs == HIDDENFIELD && labelFieldIsVisible)
  1350.   {  // if hidden field
  1351.     _ElementLabel.setAttribute("value","");                          // then set value field to empty string
  1352.     _ElementLabel.setAttribute("disabled","true");                   // and make it non-editable
  1353.   }
  1354. }
  1355.  
  1356. //--------------------------------------------------------------------
  1357. // FUNCTION:
  1358. //   toggleSubmitAs
  1359. //
  1360. // DESCRIPTION:
  1361. //   toggles the visibility of "Submit As: [menu]" that appears on 
  1362. //   the UI.  This menu is disabled in case of Update form and if
  1363. //   it is a primary key column
  1364. //
  1365. // ARGUMENTS:
  1366. //   show - boolean 
  1367. //
  1368. // RETURNS:
  1369. //   Nothing
  1370. //--------------------------------------------------------------------
  1371. function toggleSubmitAs(bShow)
  1372. {
  1373.   if (bShow)
  1374.   { 
  1375.     _SubmitAs.enabled();
  1376.   }
  1377.   else
  1378.   {
  1379.     _SubmitAs.append(" ");
  1380.     _SubmitAs.disable();
  1381.   }
  1382. }
  1383.  
  1384. //--------------------------------------------------------------------
  1385. // FUNCTION:
  1386. //   EnableDisableUpDownBtns
  1387. //
  1388. // DESCRIPTION:
  1389. //   Enable/disables the elemUp and elemDown buttons
  1390. //
  1391. // ARGUMENTS:
  1392. //   None
  1393. //
  1394. // RETURNS:
  1395. //   Nothing
  1396. //--------------------------------------------------------------------
  1397. function EnableDisableUpDownBtns()
  1398. {
  1399.   // Check if there are any columns
  1400.   if (_ColumnNames.list.length == 0 || _ColumnNames.getRowIndex() == -1)
  1401.   {
  1402.     _ElemUp.setAttribute("disabled", true);
  1403.     _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";   
  1404.     
  1405.     _ElemDown.setAttribute("disabled", true);
  1406.     _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";        
  1407.   }
  1408.   else
  1409.   {
  1410.     if(_ColumnNames.list.length == 1)
  1411.       {
  1412.       // first row, so disable the up and down buttons
  1413.       _ElemDown.setAttribute("disabled", true);
  1414.       _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";
  1415.  
  1416.       _ElemUp.setAttribute("disabled", true);
  1417.       _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";
  1418.     }  
  1419.     if(_ColumnNames.list.length-1 == _ColumnNames.getRowIndex())
  1420.     {
  1421.       // last row, so disable the down button and enable the up button
  1422.       _ElemDown.setAttribute("disabled", true);
  1423.       _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";
  1424.             
  1425.       _ElemUp.setAttribute("disabled", false);
  1426.       _ElemUp.src = "../Shared/MM/Images/btnUp.gif";
  1427.     }
  1428.     // first row, if it is disable up button and enable the down button
  1429.     else if (_ColumnNames.getRowIndex() == 0)
  1430.     {
  1431.       _ElemUp.setAttribute("disabled", true);
  1432.       _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";
  1433.       
  1434.       _ElemDown.setAttribute("disabled", false);
  1435.       _ElemDown.src = "../Shared/MM/Images/btnDown.gif";      
  1436.     }    
  1437.     else
  1438.     {
  1439.       //enable both up and down buttons
  1440.       _ElemDown.setAttribute("disabled", false);
  1441.       _ElemDown.src = "../Shared/MM/Images/btnDown.gif";
  1442.             
  1443.       _ElemUp.setAttribute("disabled", false);
  1444.       _ElemUp.src = "../Shared/MM/Images/btnUp.gif";      
  1445.     }
  1446.   }
  1447. }
  1448.  
  1449.  
  1450. //--------------------------------------------------------------------
  1451. // FUNCTION:
  1452. //   EnableDisableAddDelBtns
  1453. //
  1454. // DESCRIPTION:
  1455. //   Enable/disables the elemAdd and elemDel buttons
  1456. //
  1457. // ARGUMENTS:
  1458. //   None
  1459. //
  1460. // RETURNS:
  1461. //   Nothing
  1462. //--------------------------------------------------------------------
  1463. function EnableDisableAddDelBtns()
  1464. {
  1465.   // Check if there are any columns
  1466.   if (_ColumnNames.list.length == 0 || _ColumnNames.getRowIndex() == -1)
  1467.   {
  1468.     _ElemAdd.setAttribute("disabled", true);
  1469.     _ElemAdd.src = "../Shared/MM/Images/btnAdd_dis.gif";   
  1470.     
  1471.     _ElemDel.setAttribute("disabled", true);
  1472.     _ElemDel.src = "../Shared/MM/Images/btnDel_dis.gif";        
  1473.   }
  1474.   else
  1475.   {
  1476.     if (ColumnsToAdd.length == 0)
  1477.     {
  1478.       // no columns to add, so disable add button and enable delete button
  1479.       _ElemAdd.setAttribute("disabled", true);
  1480.       _ElemAdd.src = "../Shared/MM/Images/btnAdd_dis.gif"; 
  1481.       
  1482.       _ElemDel.setAttribute("disabled", false);
  1483.       _ElemDel.src = "../Shared/MM/Images/btnDel.gif";            
  1484.     }
  1485.     else
  1486.     {
  1487.       // enable both add and delete buttons
  1488.       _ElemAdd.setAttribute("disabled", false);
  1489.       _ElemAdd.src = "../Shared/MM/Images/btnAdd.gif"; 
  1490.     
  1491.       _ElemDel.setAttribute("disabled", false);
  1492.       _ElemDel.src = "../Shared/MM/Images/btnDel.gif";                
  1493.     }
  1494.   }
  1495. }
  1496.  
  1497. //--------------------------------------------------------------------
  1498. // FUNCTION:
  1499. //   displayDynamicDataDialog
  1500. //
  1501. // DESCRIPTION:
  1502. //   pops up the dialog allowing the user to choose dynamic data
  1503. //
  1504. // ARGUMENTS:
  1505. //   textFieldObj
  1506. //
  1507. // RETURNS:
  1508. //   Nothing
  1509. //--------------------------------------------------------------------
  1510. function displayDynamicDataDialog(textFieldObj)
  1511. {
  1512.   var serverModel = dw.getDocumentDOM().serverModel.getServerName();
  1513.   var expression = dw.showDynamicDataDialog(textFieldObj.value);
  1514.  
  1515.   if (expression)
  1516.   {
  1517. //    if (serverModel == "Cold Fusion")
  1518. //    {
  1519. //      expression = dwscripts.stripCFOutputTags(expression);
  1520. //    }
  1521.     textFieldObj.value = expression;
  1522.   }
  1523. }
  1524.  
  1525.  
  1526.  
  1527.  
  1528. //--------------------------------------------------------------------
  1529. // FUNCTION:
  1530. //   populateFormFieldStorageType
  1531. //
  1532. // DESCRIPTION:
  1533. //   This function is called by updateUI function.  It is responsible
  1534. //   for populating the Column grid.
  1535. //
  1536. // ARGUMENTS:
  1537. //   rowValObj - Column Name
  1538. //   rsName - Column Type
  1539. //   colName  - Recordset Name
  1540. //
  1541. // RETURNS:
  1542. //   Array
  1543. //--------------------------------------------------------------------
  1544. function populateFormFieldStorageType(rowValObj, rsName, colName)
  1545. {
  1546.   // note: this fn is only called when the row is first created, which is why
  1547.   // it only lists some of the available form types
  1548.   var displayType = rowValObj.displayAs.type;
  1549.   var dynDataVal = createDynamicData(rsName,colName);
  1550.   
  1551.   rowValObj.defaultStr = dynDataVal;
  1552.  
  1553.   if (displayType == "textField" || 
  1554.       displayType  == "textArea" || 
  1555.       displayType  == "hiddenField" )
  1556.   {
  1557.     rowValObj.displayAs.value = dynDataVal;
  1558.   }
  1559.   else if (displayType == "text" )
  1560.   {
  1561.     rowValObj.displayAs.text = dynDataVal;
  1562.   }
  1563.   else if (displayType == "dynamicCheckBox")
  1564.   {
  1565.     rowValObj.displayAs.checkIf = dynDataVal;
  1566.   }
  1567.  
  1568.   return rowValObj;
  1569. }
  1570.  
  1571.  
  1572. //--------------------------------------------------------------------
  1573. // FUNCTION:
  1574. //   createDynamicData
  1575. //
  1576. // DESCRIPTION:
  1577. //   Pops up the dialog allowing the user to choose dynamic data
  1578. //
  1579. // ARGUMENTS:
  1580. //   rs - Recordset
  1581. //   col - Column Name
  1582. //
  1583. // RETURNS:
  1584. //   String
  1585. //--------------------------------------------------------------------
  1586. function createDynamicData(rs,col)
  1587. {
  1588.   var retVal = "";
  1589.   if (rs){
  1590.     var colArray = dwscripts.getFieldNames(rs);
  1591.     if (dwscripts.findInArray(colArray, col) != -1){
  1592.       var paramObj = new Object();
  1593.       paramObj.sourceName = rs;
  1594.       paramObj.bindingName = col;
  1595.  
  1596.       retVal = extPart.getInsertString("", "Recordset_DataRef", paramObj);
  1597.     }
  1598.   }
  1599.   return retVal;
  1600. }
  1601.  
  1602.  
  1603. //--------------------------------------------------------------------
  1604. // FUNCTION:
  1605. //   updateDefaultFormFieldValues
  1606. //
  1607. // DESCRIPTION:
  1608. //   Goes through the default values, and replace references to the old
  1609. //   recordset with the new recordset
  1610. //
  1611. // ARGUMENTS:
  1612. //   oldRS - old Recordset
  1613. //   newRS - new Recordset
  1614. //
  1615. // RETURNS:
  1616. //   Nothing
  1617. //--------------------------------------------------------------------
  1618. function updateDefaultFormFieldValues(oldRS, newRS)
  1619. {
  1620.   var rowObjs = _ColumnNames.valueList;
  1621.   var nRows = rowObjs.length, i, fieldType, currRowObj, regExp;
  1622.  
  1623.   for (i=0;i<nRows;i++)
  1624.   {
  1625.     currRowObj = rowObjs[i];
  1626.     regExp = new RegExp(oldRS,"g");
  1627.     currRowObj.defaultStr = currRowObj.defaultStr.toString().replace(regExp,newRS);
  1628.     currRowObj.passwordStr = currRowObj.passwordStr.toString().replace(regExp,newRS);
  1629.  
  1630.     // update the current display
  1631.     switch(currRowObj.displayAs.type)
  1632.     {
  1633.       case "textField":
  1634.       case "textArea":
  1635.       case "hiddenField":
  1636.         currRowObj.displayAs.value = currRowObj.defaultStr;
  1637.         break;
  1638.       case "passwordField":
  1639.         currRowObj.passwordField.value = currRowObj.passwordStr;
  1640.         break;
  1641.       case "text":
  1642.         currRowObj.displayAs.text = currRowObj.defaultStr;
  1643.         break;
  1644.       case "radioGroup":
  1645.       case "dynamicRadioGroup":
  1646.         currRowObj.displayAs.defaultChecked = currRowObj.defaultStr;
  1647.         break;
  1648.       case "menu":
  1649.       case "dynamicMenu":
  1650.         currRowObj.displayAs.defaultSelected = currRowObj.defaultStr;
  1651.         break;
  1652.       case "dynamicCheckBox":
  1653.         currRowObj.displayAs.checkIf = currRowObj.defaultStr;
  1654.         break;
  1655.       case "default":
  1656.         break;  
  1657.     }
  1658.   } 
  1659.  
  1660. }
  1661.